package com.cy.utils;

import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;

@Data
@Accessors(chain = true)
public class JsonResult implements Serializable {
    /**
     * 成功响应码
     */
    public static final int CODE_OK = 0;
    /**
     * 失败响应码
     */
    public static final int CODE_ERR = 1;

    // 响应码
    private Integer code;
    // 提示消息
    private String msg;
    // 总记录数
    private Long count;
    // 响应数据
    private Object data;

    public static JsonResult ok() {
        return new JsonResult().setCode(CODE_OK);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult().setCode(CODE_OK).setData(data);
    }

    public static JsonResult ok(Long count, Object data) {
        return new JsonResult().setCode(CODE_OK).setCount(count).setData(data);
    }

    public static JsonResult err(String msg) {
        return new JsonResult().setCode(CODE_ERR).setData(msg);
    }

    public static JsonResult err(Integer code, String msg) {
        return new JsonResult().setCode(code).setData(msg);
    }
}
